import { groupBy, mapKeys } from 'lodash-es'
import { DiyCompTypeDataMap } from './types'
import type {IDiyBase} from "@/diy/types";


class DiyFactory {
  static create<T extends IDiyBase>(Config: new () => T) {
    return new Config()
  }
}

type DiyListType = Record<string, IDiyBase[]>
export const getDiyList = (list: (new () => IDiyBase)[]): DiyListType => {
  const instanceList = list.map((item) => {
    return DiyFactory.create(item)
  })
  const diyGroupList = groupBy(instanceList, 'type')
  return mapKeys(diyGroupList, (item: any) => {
    return DiyCompTypeDataMap[item[0].type]
  })
}
